<?php
/**
 * Pronounceable word facade class file.
 *
 * Infectamic: browser game (http://infectamic.goldzoneweb.info)
 * Copyright 2011, Loic Chardonnet
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 */

App::uses('PronounceableWord', 'Lib');

/**
 * Class for pronounceable word.
 */
class PronounceableWordFacade extends PronounceableWord {
    protected $nameToGenerate = '';

    public function __construct($nameToGenerate) {
        $this->nameToGenerate = $nameToGenerate;
        $this->finalLength = strlen($this->nameToGenerate);
    }

    /**
     * Picks randomly the first letter.
     *
     * @return string The picked letter
     */
    protected function pickFirstLetter() {
        return $this->nameToGenerate[0];
    }

    /**
     * Picks randomly a letter from the given choice.
     *
     * @param string $choiceOfLetters The given choice of letters
     * @return string The picked letter
     */
    protected function pickLetterFromGivenChoice($choiceOfLetters) {
        $letterIndexToPick = $this->currentLength;

        $pickedLetter = '';
        if ($letterIndexToPick < $this->finalLength) {
            $letterToPick = $this->nameToGenerate[$letterIndexToPick];
            if (false !== strpos($choiceOfLetters, $letterToPick)) {
                $pickedLetter = $letterToPick;
            }
        }

        return $pickedLetter;
    }
}
